The direction in degrees from the first point to the second (0 = east, counterclockwise).
dir_to(x1, y1, x2, y2) -> real| Name | Type |
|---|---|
x1 | real |
y1 | real |
x2 | real |
y2 | real |
real
The direction in degrees from one point toward another, using the engine's usual 0-is-east, counterclockwise convention. Standing exactly on the target - both points identical - returns 0 rather than an undefined angle.
The four numbers may be places (counted from the room's top-left corner, like an instance's x and y) or they may be amounts (dist_to(0, 0, dx, dy) measures how long the arrow (dx, dy) is). When both points are real positions, such as dist_to(x, y, other.x, other.y), only the difference between them matters, so it does not matter which corner the counting starts from. A fixed place written as a number is different: dist_to(0, 0, x, y) now measures from the room's top-left corner, where it used to measure from the middle of the room. The converter cannot tell that number from an amount, so it lists such calls for you to check by hand.
It counts fractions of a pixel. If the second point is only a little bit away from the first, say 0.7 pixels across and 0.3 down, you still get the true direction, so you can point something using how far it moved in one frame. The answer is accurate to about a hundredth of a degree on the Advance, not exact, and it holds for any distance between the two points - fine for aiming a turret or steering an enemy, not for anything that needs an exact angle.


dir_to only ever returns the angle half of this picture - the distance itself is dist_to.
target = instance_nearest(x, y, obj_doc_walker);
if (target != nothing) {
direction = dir_to(x, y, target.x, target.y);
}Shown here in Create, which is also where the bare target = ... declares target in the first place (see Variables, types and scope) - target is a ref<obj_doc_walker>, and .x/.y read straight through it to the instance it points at. Call the same lines again from Step to keep the turret pointed at its target every frame instead of just once.
An arctangent calculation, accurate to about 0.01°. Works for any distance between the two points. Counts fractions of a pixel: a small difference such as 0.7 across and 0.3 down gives the true angle, not 0 (east). Standing exactly on the target returns 0.